1 // Equipo Poncho, Carriel y Ruana
22 template <class T
> string
toStr(const T
&x
)
23 { stringstream s
; s
<< x
; return s
.str(); }
24 template <class T
> int toInt(const T
&x
)
25 { stringstream s
; s
<< x
; int r
; s
>> r
; return r
; }
27 #define For(i, a, b) for (int i=(a); i<(b); ++i)
28 #define foreach(x, v) for (typeof (v).begin() x = (v).begin(); x != (v).end(); ++x)
29 #define D(x) cout << #x " = " << (x) << endl;
31 const double EPS
= 1e-9;
33 int cmp(double x
, double y
= 0, double tol
= EPS
) {
34 return (x
<= y
+ tol
) ? (x
+ tol
< y
) ? -1 : 0 : 1;
37 #define INPUT_FILE "edgetown"
50 g1
[i
][j
] = min(g1
[i
][j
], g1
[i
][k
] + g1
[k
][j
]);
51 g2
[i
][j
] = min(g2
[i
][j
], g2
[i
][k
] + g2
[k
][j
]);
57 bool equal(long long a
, long long b
) {
60 if (g2
[i
][j
] >= oo
) return false;
61 long long now
= g2
[i
][j
];
62 long long cota
= g1
[i
][j
] * a
+ b
;
64 //printf("From %d to %d: now = %d, cota = %d, old = %d\n", i, j, (int)now, (int)cota, g1[i][j]);
73 freopen(INPUT_FILE
".in", "r", stdin
);
76 string s
; getline(cin
, s
);
78 For (i
, 0, n
) For(j
, 0, n
) g1
[i
][j
] = g2
[i
][j
] = oo
;
80 for (int i
= 0; i
< n
; ++i
) {
83 int first
; sin
>> first
; first
--;
85 while (sin
>> other
) {
91 for (int i
= 0; i
< n
; ++i
) {
94 int first
; sin
>> first
; first
--;
96 while (sin
>> other
) {
101 For(i
, 0, n
) g1
[i
][i
] = g2
[i
][i
] = 0;
105 if (a
== 0 and b
== 0 and n
> 1) {
110 //puts("G1"); For(i, 0, n){ For(j, 0, n) { printf("%10d", g1[i][j]); } puts(""); } puts("");
111 //puts("G2"); For(i, 0, n){ For(j, 0, n) { printf("%10d", g2[i][j]); } puts(""); } puts("");